#include <gtest/gtest.h>
#include <string>
#include "../HttpClient.h"

class CTestHttpClient: public CHttpClient
{
public:
    void SplitUrl(const string &url, string &domain,
		  string &port, string &path)
    { CHttpClient::SplitUrl(url, domain, port, path); }
};

const string rdomain = "www.google.com"; //r --> real
const string rport = "80";
const string rpath = "/app/query.php";

class CTestFixureOne: public ::testing::Test
{
};

TEST_F(CTestFixureOne, Normal)
{
    CTestHttpClient httpclient;
    string url = "HTTP://www.google.com:8080/index.html";
    string domain, port, path;
    httpclient.SplitUrl(url, domain, port, path);

    ASSERT_TRUE(domain == "www.google.com");
    ASSERT_TRUE(port == "8080");
    ASSERT_TRUE(path == "/index.html");
}

TEST_F(CTestFixureOne, NoSchemem)
{
    CTestHttpClient httpclient;
    string domain, port, path;
    string url = rdomain + ":" + rport + rpath;
    httpclient.SplitUrl(url, domain, port, path);

    ASSERT_TRUE(domain == rdomain);
    ASSERT_TRUE(port == rport);
    ASSERT_TRUE(path == rpath);
}

TEST_F(CTestFixureOne, WeirdSchemem)
{
    CTestHttpClient httpclient;
    string domain, port, path;
    string url = "abc://" + rdomain + ":" + rport + rpath;
    httpclient.SplitUrl(url, domain, port, path);

    ASSERT_TRUE(true);
}

TEST_F(CTestFixureOne, NoPort)
{
    CTestHttpClient httpclient;
    string domain, port, path;
    string url = rdomain + rpath;
    httpclient.SplitUrl(url, domain, port, path);

    ASSERT_TRUE(domain == rdomain);
    ASSERT_TRUE(port == "");
    ASSERT_TRUE(path == rpath);
}

TEST_F(CTestFixureOne, NoPath)
{
    CTestHttpClient httpclient;
    string domain, port, path;
    string url = rdomain;
    httpclient.SplitUrl(url, domain, port, path);

    ASSERT_TRUE(domain == rdomain);
    ASSERT_TRUE(port == "");
    ASSERT_TRUE(path == "");
}

TEST_F(CTestFixureOne, NoUrl)
{
    CTestHttpClient httpclient;

    const string emptystring;
    string domain("abc"), port("abc"), path("abc");
    httpclient.SplitUrl(emptystring, domain, port, path);

    ASSERT_TRUE(domain == emptystring);
    ASSERT_TRUE(port == emptystring);
    ASSERT_TRUE(path == emptystring);
}

